<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8" >
    <meta http-equiv="X-UA-Compatible" content="IE=11,IE=10,IE=9,IE=8" >
    <meta name="baidu-site-verification" content="dIcXMeY8Ya" />
    
    <title>hibernate-annotation | 即将拥有人鱼线丶</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0" >
    <meta name="keywords" content="FutaoSmile, 前端, Web, 付韬, 个人博客" >
    <meta name="description" content="付韬FutaoSmile" >

    
    <link rel="alternative" href="/atom.xml" title="即将拥有人鱼线丶" type="application/atom+xml" >
    
    
    <link rel="shortcut icon" href="/coder957/coder957/favicon.ico" >
    
    <link rel="stylesheet" href="/coder957/css/style.css">
    <!--[if lt IE 9]>
    <script src="/coder957/js/html5.js"></script>
    <![endif]-->
    
<script>
    var _hmt = _hmt || [];
    (function() {
        var hm = document.createElement("script");
        hm.src = "//hm.baidu.com/hm.js?fd459238242776d173cdc64918fb32f2";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
    })();
</script>


</head>

<body class="home">
    <!--[if lt IE 9]>
    <div class="browsehappy">
        当前网页 <strong>不支持</strong>
        你正在使用的浏览器. 为了正常的访问, 请 <a href="http://browsehappy.com/">升级你的浏览器</a>.
    </div>
    <![endif]-->

    <!-- 博客头部 -->
    <header class="header">
    <section class="container header-main">
        <div class="logo">
            <a href="/coder957/">
                <div class="cover">
                    <span class="name">即将拥有人鱼线丶</span>
                    <span class="description">FutaoSmile</span>
                </div>
            </a>
        </div>
        <div class="dropnav icon-paragraph-justify" id="JELON__btnDropNav"></div>
        <ul class="menu hidden" id="JELON__menu">
            
                <li rel="/coder957/2017/09/28/hibernate-annotation/index.html" class="item ">
                    <a href="/coder957/" title="首页" class="icon-home">&nbsp;首页</a>
                </li>
                
                <li rel="/coder957/2017/09/28/hibernate-annotation/index.html" class="item ">
                    <a href="/coder957/lab/" title="实验室" class="icon-lab">&nbsp;实验室</a>
                </li>
                
                <li rel="/coder957/2017/09/28/hibernate-annotation/index.html" class="item ">
                    <a href="/coder957/about/" title="关于" class="icon-about">&nbsp;关于</a>
                </li>
                
                <li rel="/coder957/2017/09/28/hibernate-annotation/index.html" class="item ">
                    <a href="/coder957/comment/" title="留言" class="icon-comment">&nbsp;留言</a>
                </li>
                
        </ul>
        <div class="profile clearfix">
            <div class="feeds fl">
                
                    
                        <p class="links">
                            
                                <a href="https://github.com/FutaoSmile" target="_blank">
                                    Github
                                </a>
                                |
                                    
                                        
                                <a href="http://www.jianshu.com/u/9e2e579df7dd" target="_blank">
                                    简书
                                </a>
                                
                                        
                        </p>
                        <p class="sns">
                            
                                <a href="http://weibo.com/u/2379076265?refer_flag=1001030001_&amp;nick=FutaoSmile%E4%B8%B6" class="sinaweibo" target="_blank"><b>■</b> 新浪微博</a>
                                
                                <a href="https://gitee.com/FutaoSmile" class="qqweibo" target="_blank"><b>■</b> 码云</a>
                                
                                    <!-- <a href="javascript: void(0);" class="wechat">
                        <b>■</b>
                        公众号
                        <span class="popover">
                            <img src="/coder957/img/wechat_mp.jpg" width="120" height="120" alt="我的微信订阅号">
                            <i class="arrow"></i>
                        </span>
                    </a> -->
                        </p>
                        
            </div>
            <div class="avatar fr">
                <img src="/coder957/img/head.png" alt="avatar" title="Jelon">
            </div>
        </div>
    </section>
</header>

    <!-- 博客正文 -->
    <div class="container body clearfix">
        <section class="content">
            <div class="content-main widget">
                <!-- 文章页 -->
<!-- 文章 -->
<article class="post article">
    <header class="text-center">
        <h3 class="post-title"><span>hibernate-annotation</span></h3>
    </header>
    <p class="post-meta text-center">
        FutaoSmile丶 发表于
            <time datetime="2017-09-28T07:04:20.610Z">2017-09-28</time>
    </p>
    <div class="post-content">
        <blockquote>
<p><a href="http://www.imooc.com/learn/524" target="_blank" rel="external">课程地址</a><br><a href="https://gitee.com/FutaoSmile/hibernate-senior-annotation" target="_blank" rel="external">项目地址</a></p>
</blockquote>
<a id="more"></a>
<h3 id="使用hibernate注解的目的"><a href="#使用hibernate注解的目的" class="headerlink" title="使用hibernate注解的目的"></a>使用hibernate注解的目的</h3><p>为了简化ORM映射文件(*.hbm)繁琐的配置。<br>注解需要做的是映射文件要做的。</p>
<h3 id="JPA与Hibernate"><a href="#JPA与Hibernate" class="headerlink" title="JPA与Hibernate"></a>JPA与Hibernate</h3><p>Java Persistence API<br>Java持久化接口<br>JPA是标准接口，HIbernate是JPA的实现，但是功能是JAP的超集。</p>
<h4 id="Hibernate注解分类"><a href="#Hibernate注解分类" class="headerlink" title="Hibernate注解分类"></a>Hibernate注解分类</h4><ol>
<li>类级别注解<ol>
<li>@Entity</li>
<li>@Table</li>
<li>@Embeddable(嵌入类)</li>
</ol>
</li>
<li>属性级别注解</li>
<li>映射关系注解</li>
</ol>
<h2 id="一，类级别注解"><a href="#一，类级别注解" class="headerlink" title="一，类级别注解"></a>一，类级别注解</h2><h3 id="1-Entity"><a href="#1-Entity" class="headerlink" title="1.   @Entity"></a>1.   @Entity</h3><p><img src="http://upload-images.jianshu.io/upload_images/1846623-cb443ecbc0c8b93d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="Entity"></p>
<p><strong>1.  编写Entity</strong><br>      设置主键，打在getter上@Id<br><strong>2.  class添加注解@Entity</strong><br><strong>3.  在核心配置文件中配置</strong><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">&lt;!--映射文件--&gt;</div><div class="line">        &lt;mapping class=&quot;Entity.Student&quot;/&gt;</div></pre></td></tr></table></figure></p>
<h3 id="2-Table"><a href="#2-Table" class="headerlink" title="2.   @Table"></a>2.   @Table</h3><p><img src="http://upload-images.jianshu.io/upload_images/1846623-df9f33f405412c6b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="@Table"></p>
<p>@Tabel(name=””)和@Entity(name=””)</p>
<blockquote>
<p>@Table’s name attribute is the actual table name. @Entitiy’s name is useful if you have two @Entity classes with the same name and you need a way to differentiate them when running queries.<br><a href="https://stackoverflow.com/questions/18732646/name-attribute-in-entity-and-table" target="_blank" rel="external">From Stack Overflow</a></p>
</blockquote>
<h3 id="3-Embeddable"><a href="#3-Embeddable" class="headerlink" title="3.   @Embeddable"></a>3.   @Embeddable</h3><p>表示一个非Entity类可以嵌套到另一个Entity中，作为另一个Entity的属性。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div></pre></td><td class="code"><pre><div class="line">package Entity;</div><div class="line"></div><div class="line">import javax.persistence.Embeddable;</div><div class="line"></div><div class="line">/**</div><div class="line"> * Created by futao on 2017/9/27.</div><div class="line"> */</div><div class="line"></div><div class="line">/**</div><div class="line"> * 嵌入类，不会生成表，可能在其他表作为属性存在</div><div class="line"> */</div><div class="line">@Embeddable</div><div class="line">public class Gf &#123;</div><div class="line">    private String name;</div><div class="line">    private int age;</div><div class="line"></div><div class="line">    public String getName() &#123;</div><div class="line">        return name;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public void setName(String name) &#123;</div><div class="line">        this.name = name;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public int getAge() &#123;</div><div class="line">        return age;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public void setAge(int age) &#123;</div><div class="line">        this.age = age;</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div><div class="line">90</div><div class="line">91</div><div class="line">92</div><div class="line">93</div><div class="line">94</div><div class="line">95</div><div class="line">96</div><div class="line">97</div><div class="line">98</div><div class="line">99</div><div class="line">100</div><div class="line">101</div><div class="line">102</div><div class="line">103</div><div class="line">104</div><div class="line">105</div><div class="line">106</div><div class="line">107</div><div class="line">108</div><div class="line">109</div></pre></td><td class="code"><pre><div class="line">package Entity;</div><div class="line"></div><div class="line">/**</div><div class="line"> * Created by futao on 2017/9/26.</div><div class="line"> */</div><div class="line"></div><div class="line">import javax.persistence.Column;</div><div class="line">import javax.persistence.Entity;    //JPA注解</div><div class="line">import javax.persistence.Id;</div><div class="line">import javax.persistence.Table;</div><div class="line">import java.sql.Timestamp;</div><div class="line"></div><div class="line"></div><div class="line">/**</div><div class="line"> * 学生实体类</div><div class="line"> */</div><div class="line">@Entity</div><div class="line">@Table(name = &quot;imooc_student1&quot;)</div><div class="line">public class Student &#123;</div><div class="line">    /**</div><div class="line">     * 主键</div><div class="line">     */</div><div class="line">    @Column(name = &quot;sid&quot;)</div><div class="line">    private int sid;</div><div class="line">    /**</div><div class="line">     * 姓名</div><div class="line">     */</div><div class="line">    @Column(name = &quot;sname&quot;)</div><div class="line">    private String sname;</div><div class="line">    /**</div><div class="line">     * 性别</div><div class="line">     */</div><div class="line">    @Column(name = &quot;gender&quot;)</div><div class="line">    private String gender;</div><div class="line">    /**</div><div class="line">     * 生日</div><div class="line">     */</div><div class="line">    @Column(name = &quot;birthday&quot;)</div><div class="line">    private Timestamp birthday;</div><div class="line">    /**</div><div class="line">     * 专业</div><div class="line">     */</div><div class="line">    @Column(name = &quot;major&quot;)</div><div class="line">    private String major;</div><div class="line">    /**</div><div class="line">     * 地址</div><div class="line">     */</div><div class="line">    private String address;</div><div class="line"></div><div class="line">    //组件属性</div><div class="line">    private Gf gf;</div><div class="line"></div><div class="line">    @Id</div><div class="line">    public int getSid() &#123;</div><div class="line">        return sid;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public void setSid(int sid) &#123;</div><div class="line">        this.sid = sid;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public Gf getGf() &#123;</div><div class="line">        return gf;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public void setGf(Gf gf) &#123;</div><div class="line">        this.gf = gf;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public String getSname() &#123;</div><div class="line">        return sname;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public void setSname(String sname) &#123;</div><div class="line">        this.sname = sname;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public String getGender() &#123;</div><div class="line">        return gender;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public void setGender(String gender) &#123;</div><div class="line">        this.gender = gender;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public Timestamp getBirthday() &#123;</div><div class="line">        return birthday;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public void setBirthday(Timestamp birthday) &#123;</div><div class="line">        this.birthday = birthday;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public String getMajor() &#123;</div><div class="line">        return major;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public void setMajor(String major) &#123;</div><div class="line">        this.major = major;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public String getAddress() &#123;</div><div class="line">        return address;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public void setAddress(String address) &#123;</div><div class="line">        this.address = address;</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h2 id="二，属性级别注解"><a href="#二，属性级别注解" class="headerlink" title="二，属性级别注解"></a>二，属性级别注解</h2><blockquote>
<p>添加方式<br>1.写在属性字段上面<br>2.写在getter上面</p>
</blockquote>
<p><strong>@Id</strong><br>@SequenceGenerator<br><strong>@GeneratedValue</strong><br><strong>@Column</strong><br><strong>@Embedded</strong><br><strong>@EmbeddedId</strong><br>@Lob<br>@Version<br>@Basic<br><strong>@Transient</strong></p>
<h3 id="1-Id"><a href="#1-Id" class="headerlink" title="1.  @Id"></a>1.  @Id</h3><p><img src="http://upload-images.jianshu.io/upload_images/1846623-96fc88bec0ea3237.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="@Id"><br>可以给一个Entity设置两个主键，不过要实现Serializable接口</p>
<h3 id="2-GeneratedValue"><a href="#2-GeneratedValue" class="headerlink" title="2.  @GeneratedValue"></a>2.  @GeneratedValue</h3><p><img src="http://upload-images.jianshu.io/upload_images/1846623-521b9215ee805e92.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="GeneratedValue"></p>
<p><img src="http://upload-images.jianshu.io/upload_images/1846623-f40d660d03bfc70e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="example"></p>
<h3 id="3-GeneratedValue"><a href="#3-GeneratedValue" class="headerlink" title="3.  @GeneratedValue"></a>3.  @GeneratedValue</h3><h3 id="4-Column"><a href="#4-Column" class="headerlink" title="4.  @Column"></a>4.  @Column</h3><p><img src="http://upload-images.jianshu.io/upload_images/1846623-28511b36249f1ea8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="Column"></p>
<h3 id="5-Embedded-EmbeddedId"><a href="#5-Embedded-EmbeddedId" class="headerlink" title="5.  @Embedded,@EmbeddedId"></a>5.  @Embedded,@EmbeddedId</h3><p>打在被标记为@Embeddable的嵌入类的实例上，或者getter上</p>
<p><img src="http://upload-images.jianshu.io/upload_images/1846623-c57301315823898e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="@Embedded"></p>
<h3 id="6-Transient"><a href="#6-Transient" class="headerlink" title="6.  @Transient"></a>6.  @Transient</h3><p><img src="http://upload-images.jianshu.io/upload_images/1846623-874ccdee104235b2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="@Transient"></p>
<h2 id="三，关系映射级别注解"><a href="#三，关系映射级别注解" class="headerlink" title="三，关系映射级别注解"></a>三，关系映射级别注解</h2><p><img src="http://upload-images.jianshu.io/upload_images/1846623-e90ba5a6e4fdfc65.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="关系映射级别注解"></p>
<h4 id="1-一对一单向外键关联-两张表都要在hibernate住配置文件中进行配置"><a href="#1-一对一单向外键关联-两张表都要在hibernate住配置文件中进行配置" class="headerlink" title="1.  一对一单向外键关联(两张表都要在hibernate住配置文件中进行配置)"></a>1.  一对一单向外键关联(两张表都要在hibernate住配置文件中进行配置)</h4><p><img src="http://upload-images.jianshu.io/upload_images/1846623-db01ac12f83fe164.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="一对一单向外键关联"></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div></pre></td><td class="code"><pre><div class="line">//主表</div><div class="line">package Entity;</div><div class="line"></div><div class="line">import javax.persistence.*;</div><div class="line">import java.sql.Timestamp;</div><div class="line"></div><div class="line">/**</div><div class="line"> * Created by futao on 2017/9/27.</div><div class="line"> */</div><div class="line">@Entity</div><div class="line">@Table(name = &quot;imooc_student&quot;)</div><div class="line">public class Student &#123;</div><div class="line">    /**</div><div class="line">     * 主键，学号</div><div class="line">     */</div><div class="line">    @Id</div><div class="line">    @GeneratedValue</div><div class="line">    private int sid;</div><div class="line">    /**</div><div class="line">     * 性别</div><div class="line">     */</div><div class="line">    private String gender;</div><div class="line">    /**</div><div class="line">     * 生日</div><div class="line">     */</div><div class="line">    private Timestamp birthday;</div><div class="line">    /**</div><div class="line">     * 专业</div><div class="line">     */</div><div class="line">    private String major;</div><div class="line">    /**</div><div class="line">     * 身份证对象</div><div class="line">     */</div><div class="line">    @OneToOne(cascade = CascadeType.ALL)</div><div class="line">    @JoinColumn(name = &quot;pid&quot;,unique = true)</div><div class="line">    private IdCard idCard;</div><div class="line"></div><div class="line">    public IdCard getIdCard() &#123;</div><div class="line">        return idCard;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public void setIdCard(IdCard idCard) &#123;</div><div class="line">        this.idCard = idCard;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public int getSid() &#123;</div><div class="line">        return sid;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public void setSid(int sid) &#123;</div><div class="line">        this.sid = sid;</div><div class="line">    &#125;</div><div class="line"></div><div class="line"></div><div class="line">    public String getGender() &#123;</div><div class="line">        return gender;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public void setGender(String gender) &#123;</div><div class="line">        this.gender = gender;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public Timestamp getBirthday() &#123;</div><div class="line">        return birthday;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public void setBirthday(Timestamp birthday) &#123;</div><div class="line">        this.birthday = birthday;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public String getMajor() &#123;</div><div class="line">        return major;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public void setMajor(String major) &#123;</div><div class="line">        this.major = major;</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div></pre></td><td class="code"><pre><div class="line">//关联表</div><div class="line">package Entity;</div><div class="line"></div><div class="line">import org.hibernate.annotations.GenericGenerator;</div><div class="line"></div><div class="line">import javax.persistence.*;</div><div class="line"></div><div class="line">/**</div><div class="line"> * Created by futao on 2017/9/27.</div><div class="line"> */</div><div class="line">@Entity</div><div class="line">@Table(name = &quot;imoooc_id_card&quot;)</div><div class="line">public class IdCard &#123;</div><div class="line">    @Id</div><div class="line">    @GeneratedValue(generator = &quot;pid&quot;)</div><div class="line">    @GenericGenerator(name=&quot;pid&quot;,strategy = &quot;assigned&quot;)</div><div class="line">    @Column(length = 18)</div><div class="line">    private String pid;</div><div class="line">    private String sname;</div><div class="line">    private String address;</div><div class="line"></div><div class="line">    public String getPid() &#123;</div><div class="line">        return pid;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public void setPid(String pid) &#123;</div><div class="line">        this.pid = pid;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public String getSname() &#123;</div><div class="line">        return sname;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public void setSname(String sname) &#123;</div><div class="line">        this.sname = sname;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public String getAddress() &#123;</div><div class="line">        return address;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public void setAddress(String address) &#123;</div><div class="line">        this.address = address;</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line">//Test</div><div class="line">    @Test</div><div class="line">    fun dbtest() &#123;</div><div class="line">        session.save(IdCard().apply &#123;</div><div class="line">            pid = &quot;11&quot;</div><div class="line">            sname = &quot;熊anger&quot;</div><div class="line">            address = &quot;上海小二房&quot;</div><div class="line">        &#125;)</div><div class="line">        session.save(Student().apply &#123;</div><div class="line">            gender = &quot;男&quot;</div><div class="line">            birthday = Timestamp(DateTime.now().millis)</div><div class="line">            major = &quot;计算机&quot;</div><div class="line">            idCard = session.get(Student::class.java, 2) as IdCard</div><div class="line">        &#125;)</div><div class="line">    &#125;</div></pre></td></tr></table></figure>
<h4 id="2-不推荐使用双向外键关联"><a href="#2-不推荐使用双向外键关联" class="headerlink" title="2.  不推荐使用双向外键关联"></a>2.  不推荐使用双向外键关联</h4><h3 id="3-多对一单向外键关联"><a href="#3-多对一单向外键关联" class="headerlink" title="3.  多对一单向外键关联"></a>3.  多对一单向外键关联</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div></pre></td><td class="code"><pre><div class="line">//多的那一方</div><div class="line">package ManyToOne;</div><div class="line"></div><div class="line">import javax.persistence.*;</div><div class="line">import java.sql.Timestamp;</div><div class="line"></div><div class="line">/**</div><div class="line"> * Created by futao on 2017/9/28.</div><div class="line"> */</div><div class="line"></div><div class="line">/**</div><div class="line"> * 学生实体类</div><div class="line"> */</div><div class="line">@Entity</div><div class="line">@Table(name = &quot;imooc_senior_student&quot;)</div><div class="line">public class Student &#123;</div><div class="line"></div><div class="line">    @Id</div><div class="line">    @GeneratedValue</div><div class="line">    private int sid;</div><div class="line">    private String gender;</div><div class="line">    private Timestamp birthday;</div><div class="line">    private String major;</div><div class="line"></div><div class="line">    /**</div><div class="line">     * 一对多单向外键关联关系</div><div class="line">     * 级联关系：全级连</div><div class="line">     * 抓取策略</div><div class="line">     */</div><div class="line">//@joinColumn(name=&quot;对用生成的表中的字段名&quot;,referencedColumnName=&quot;一的那一方的主键名&quot;)</div><div class="line">    @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)</div><div class="line">    @JoinColumn(name = &quot;fuckyou&quot;,referencedColumnName =&quot;cid&quot; )</div><div class="line">    private Classroom classroom;</div><div class="line"></div><div class="line">    public Classroom getClassroom() &#123;</div><div class="line">        return classroom;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public void setClassroom(Classroom classroom) &#123;</div><div class="line">        this.classroom = classroom;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public int getSid() &#123;</div><div class="line">        return sid;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public void setSid(int sid) &#123;</div><div class="line">        this.sid = sid;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public String getGender() &#123;</div><div class="line">        return gender;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public void setGender(String gender) &#123;</div><div class="line">        this.gender = gender;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public Timestamp getBirthday() &#123;</div><div class="line">        return birthday;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public void setBirthday(Timestamp birthday) &#123;</div><div class="line">        this.birthday = birthday;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public String getMajor() &#123;</div><div class="line">        return major;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public void setMajor(String major) &#123;</div><div class="line">        this.major = major;</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div></pre></td><td class="code"><pre><div class="line">//一的那一方</div><div class="line">package ManyToOne;</div><div class="line"></div><div class="line">import org.hibernate.annotations.GenericGenerator;</div><div class="line"></div><div class="line">import javax.persistence.*;</div><div class="line"></div><div class="line">/**</div><div class="line"> * Created by futao on 2017/9/28.</div><div class="line"> */</div><div class="line"></div><div class="line">/**</div><div class="line"> * 班级实体类</div><div class="line"> */</div><div class="line">@Entity</div><div class="line">@Table(name = &quot;imooc_senior_classroom&quot;)</div><div class="line">public class Classroom &#123;</div><div class="line">    @Id</div><div class="line">    @GeneratedValue(generator = &quot;cid&quot;)</div><div class="line">    @GenericGenerator(name = &quot;cid&quot;,strategy = &quot;assigned&quot;)</div><div class="line">    @Column(length = 4)</div><div class="line">    private String cid;</div><div class="line">    private String cname;</div><div class="line"></div><div class="line">    public String getCid() &#123;</div><div class="line">        return cid;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public void setCid(String cid) &#123;</div><div class="line">        this.cid = cid;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public String getCname() &#123;</div><div class="line">        return cname;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public void setCname(String cname) &#123;</div><div class="line">        this.cname = cname;</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h4 id="4-多对多单向外键"><a href="#4-多对多单向外键" class="headerlink" title="4.  多对多单向外键"></a>4.  多对多单向外键</h4><p>多对多会生成一张中间表存储对应关系</p>
<p><img src="http://upload-images.jianshu.io/upload_images/1846623-b1e979f51d27db0e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="ManyToMany"></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div></pre></td><td class="code"><pre><div class="line">package Many2Many;</div><div class="line"></div><div class="line">import javax.persistence.*;</div><div class="line">import java.sql.Timestamp;</div><div class="line">import java.util.Set;</div><div class="line"></div><div class="line">/**</div><div class="line"> * Created by futao on 2017/9/28.</div><div class="line"> */</div><div class="line">@Entity</div><div class="line">@Table(name = &quot;many2many_student&quot;)</div><div class="line">public class Student &#123;</div><div class="line"></div><div class="line">    @Id</div><div class="line">    @GeneratedValue</div><div class="line">    private int sid;</div><div class="line">    private String name;</div><div class="line">    private String gender;</div><div class="line">    private Timestamp birthday;</div><div class="line">    private String major;</div><div class="line"></div><div class="line">    /**</div><div class="line">     * 学生持有教师的集合</div><div class="line">     */</div><div class="line">    @ManyToMany</div><div class="line">    @JoinTable(</div><div class="line">            //中间表的名字</div><div class="line">            name = &quot;student_teacher&quot;,</div><div class="line">            joinColumns = &#123;@JoinColumn(name = &quot;sid&quot;)&#125;,</div><div class="line">            inverseJoinColumns = &#123;@JoinColumn(name = &quot;tid&quot;)&#125;</div><div class="line">    )</div><div class="line">    private Set&lt;Teacher&gt; teacherSet;</div><div class="line"></div><div class="line">    public Set&lt;Teacher&gt; getTeacherSet() &#123;</div><div class="line">        return teacherSet;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public void setTeacherSet(Set&lt;Teacher&gt; teacherSet) &#123;</div><div class="line">        this.teacherSet = teacherSet;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public int getSid() &#123;</div><div class="line">        return sid;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public void setSid(int sid) &#123;</div><div class="line">        this.sid = sid;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public String getName() &#123;</div><div class="line">        return name;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public void setName(String name) &#123;</div><div class="line">        this.name = name;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public String getGender() &#123;</div><div class="line">        return gender;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public void setGender(String gender) &#123;</div><div class="line">        this.gender = gender;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public Timestamp getBirthday() &#123;</div><div class="line">        return birthday;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public void setBirthday(Timestamp birthday) &#123;</div><div class="line">        this.birthday = birthday;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public String getMajor() &#123;</div><div class="line">        return major;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public void setMajor(String major) &#123;</div><div class="line">        this.major = major;</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div></pre></td><td class="code"><pre><div class="line">package Many2Many;</div><div class="line"></div><div class="line">import org.hibernate.annotations.GenericGenerator;</div><div class="line"></div><div class="line">import javax.persistence.*;</div><div class="line"></div><div class="line">/**</div><div class="line"> * Created by futao on 2017/9/28.</div><div class="line"> */</div><div class="line">@Entity</div><div class="line">@Table(name = &quot;many2many_teacher&quot;)</div><div class="line">public class Teacher &#123;</div><div class="line">    @Id</div><div class="line">    @GeneratedValue(generator = &quot;tid&quot;)</div><div class="line">    @GenericGenerator(name = &quot;tid&quot;, strategy = &quot;assigned&quot;)</div><div class="line">    @Column(length = 4)</div><div class="line">    private String tid;</div><div class="line">    private String tname;</div><div class="line"></div><div class="line">    public String getTid() &#123;</div><div class="line">        return tid;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public void setTid(String tid) &#123;</div><div class="line">        this.tid = tid;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public String getTname() &#123;</div><div class="line">        return tname;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public void setTname(String tname) &#123;</div><div class="line">        this.tname = tname;</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div></pre></td><td class="code"><pre><div class="line">@Test</div><div class="line">    fun many2many()&#123;</div><div class="line">        val t1=Teacher().apply &#123;</div><div class="line">            tid=&quot;T001&quot;</div><div class="line">            tname=&quot;张老师&quot;</div><div class="line">        &#125;</div><div class="line">        val t2=Teacher().apply &#123;</div><div class="line">            tid=&quot;t999&quot;</div><div class="line">            tname=&quot;吴彦祖&quot;</div><div class="line">        &#125;</div><div class="line"></div><div class="line">        val teachers=HashSet&lt;Teacher&gt;()</div><div class="line">        teachers.add(t1)</div><div class="line">        teachers.add(t2)</div><div class="line"></div><div class="line">        val s1=Many2Many.Student().apply &#123;</div><div class="line">            name=&quot;熊老一&quot;</div><div class="line">            gender=&quot;男&quot;</div><div class="line">            birthday= Timestamp(DateTime.now().millis)</div><div class="line">            major=&quot;计算机&quot;</div><div class="line">            teacherSet=teachers</div><div class="line">        &#125;</div><div class="line">        val s2= Many2Many.Student().apply &#123;</div><div class="line">            name=&quot;熊老二&quot;</div><div class="line">            gender=&quot;男&quot;</div><div class="line">            birthday= Timestamp(DateTime.now().millis)</div><div class="line">            major=&quot;软件工程&quot;</div><div class="line">        &#125;</div><div class="line">        val s3=Many2Many.Student().apply &#123;</div><div class="line">            name=&quot;李子&quot;</div><div class="line">            gender=&quot;女&quot;</div><div class="line">            birthday= Timestamp(DateTime.now().millis)</div><div class="line">            major=&quot;建筑学&quot;</div><div class="line">            teacherSet=teachers</div><div class="line">        &#125;</div><div class="line"></div><div class="line">        session.save(t1)</div><div class="line">        session.save(t2)</div><div class="line">        session.save(s1)</div><div class="line">        session.save(s2)</div><div class="line">        session.save(s3)</div><div class="line">    &#125;</div></pre></td></tr></table></figure>
<h4 id="5-多对多双向外键关联"><a href="#5-多对多双向外键关联" class="headerlink" title="5.  多对多双向外键关联"></a>5.  多对多双向外键关联</h4><p><img src="http://upload-images.jianshu.io/upload_images/1846623-5d2798ca455ba1b8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="Many2Many"></p>
<h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><p><img src="http://upload-images.jianshu.io/upload_images/1846623-fc7c6207d8e27ea0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p><img src="http://upload-images.jianshu.io/upload_images/1846623-b910558df29c960d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>

    </div>
    <p class="post-meta">
        <span class="post-cat">分类：
            <a class="cat-link" href="/coder957/categories/Java/">Java</a>|<a class="cat-link" href="/coder957/categories/Java/学习/">学习</a>
        </span>
        <span class="post-tags">
            标签：
            
    
        <a href="/coder957/tags/Hibernate/" title="Hibernate">Hibernate</a>
    

        </span>
    </p>
</article>
<!-- 分享按钮 -->

  <div class="article-share clearfix text-center">
    <div class="share-area">
      <span class="share-txt">分享到：</span>
      <a href="javascript: window.open('http://service.weibo.com/share/share.php?url=' + encodeURIComponent(location.href) + '&title=' + document.title + '&language=zh_cn');" class="share-icon weibo"></a>
      <a href="javascript: alert('请复制链接到微信并发送');" class="share-icon wechat"></a>
      <a href="javascript: window.open('http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=' + encodeURIComponent(location.href) + '&title=' + document.title);" class="share-icon qqzone"></a>
      <a href="javascript: window.open('http://connect.qq.com/widget/shareqq/index.html?url=' + encodeURIComponent(location.href) + '&desc=Jelon个人博客&title=' + document.title + '&callback=' + encodeURIComponent(location.href));" class="share-icon qq"></a>
      <a href="javascript: window.open('http://shuo.douban.com/!service/share?href=' + encodeURIComponent(location.href) + '&name=' + document.title + '&text=' + document.title);" class="share-icon douban"></a>
    </div>
  </div>


    <!-- 上一篇/下一篇 -->

<div class="article-nav clearfix">
    
    <span class="prev fl">
        上一篇<br >
        <a href="/coder957/2017/09/29/Spring入门/">
            
                Spring入门
            
        </a>
    </span>
    

    
    <span class="next fr">
        下一篇<br >
        <a href="/coder957/2017/09/26/Hibernate-Entity-hbm-xml实现-intellij-kotlin入门级/">
            
                Hibernate-Entity.hbm.xml实现-intellij-kotlin入门级
            
        </a>
    </span>
    
</div>

        <!-- 文章评论 -->
        
  <script src="/coder957/js/comment.js"></script>
  <div id="comments" class="comment">
    <!--
    <div class="sign-bar">
      GitHub 已登录!
      <span class="sign-link">登出</span>
    </div>
    <section class="box">
      <div class="com-avatar"><img src="/img/jelon.jpg" alt="avatar"></div>
      <div class="com-text">
        <div class="main">
          <textarea class="text-area-edited show" placeholder="欢迎评论！"></textarea>
          <div class="text-area-preview"></div>
        </div>
        <div class="switch">
          <div class="switch-item on">编辑</div>
          <div class="switch-item">预览</div>
        </div>
        <div class="button">提交</div>
      </div>
    </section>
    <section class="tips">注：评论支持 markdown 语法！</section>
    <section class="list-wrap">
      <ul class="list">
        <li>
          <div class="user-avatar">
            <a href="/">
              <img src="/img/jelon.jpg" alt="user-avatar">
            </a>
          </div>
          <div class="user-comment">
            <div class="user-comment-header">
              <span class="post-name">张德龙</span>
              <span class="post-time">2017年12月12日</span>
              <span class="like liked">已赞</span>
              <span class="like-num">2</span>
            </div>
            <div class="user-comment-body">333333</div>
          </div>
        </li>
        <li>
          <div class="user-avatar">
            <a href="/">
              <img src="/img/jelon.jpg" alt="user-avatar">
            </a>
          </div>
          <div class="user-comment">
            <div class="user-comment-header">
              <span class="post-name">刘德华</span>
              <span class="post-time">2017年12月12日</span>
              <span class="like">点赞</span>
              <span class="like-num">2</span>
            </div>
            <div class="user-comment-body">vvvvv</div>
          </div>
        </li>
      </ul>
      <div class="page-nav">
        <a href="javascript: void(0);" class="item">1</a>
        <a href="javascript: void(0);" class="item">2</a>
        <a href="javascript: void(0);" class="item current">3</a>
      </div>
    </section>
    -->
  </div>
  <script>
  JELON.Comment({
    container: 'comments',
    label: 'hibernate-annotation' || '2017/09/28/hibernate-annotation/',
    owner: 'FutaoSmile',
    repo: 'blog_comments',
    clientId: '149ec394071cfd7f0f47',
    clientSecret: 'd1c988f53efa3f0f8651799f8212cc8e2cab24b9'
  });
  </script>


            </div>

        </section>
        <!-- 侧栏部分 -->
<aside class="sidebar">
    <section class="widget">
        <h3 class="widget-hd"><strong>文章分类</strong></h3>
        <!-- 文章分类 -->
<ul class="widget-bd">
    
    <li>
        <a href="/coder957/categories/后端/">后端</a>
        <span class="badge">(5)</span>
    </li>
    
    <li>
        <a href="/coder957/categories/Java/">Java</a>
        <span class="badge">(8)</span>
    </li>
    
    <li>
        <a href="/coder957/categories/Web技术/">Web技术</a>
        <span class="badge">(3)</span>
    </li>
    
    <li>
        <a href="/coder957/categories/后端/Java/">Java</a>
        <span class="badge">(5)</span>
    </li>
    
    <li>
        <a href="/coder957/categories/GIt/">GIt</a>
        <span class="badge">(1)</span>
    </li>
    
    <li>
        <a href="/coder957/categories/Java/Spring/">Spring</a>
        <span class="badge">(3)</span>
    </li>
    
    <li>
        <a href="/coder957/categories/Java/学习/">学习</a>
        <span class="badge">(5)</span>
    </li>
    
    <li>
        <a href="/coder957/categories/Web技术/Java/">Java</a>
        <span class="badge">(1)</span>
    </li>
    
    <li>
        <a href="/coder957/categories/Web技术/Kotlin/">Kotlin</a>
        <span class="badge">(1)</span>
    </li>
    
    <li>
        <a href="/coder957/categories/GIt/Web技术/">Web技术</a>
        <span class="badge">(1)</span>
    </li>
    
    <li>
        <a href="/coder957/categories/学习/">学习</a>
        <span class="badge">(1)</span>
    </li>
    
</ul>
    </section>

    
    <section class="widget">
        <h3 class="widget-hd"><strong>热门标签</strong></h3>
        <!-- 文章标签 -->
<div class="widget-bd tag-wrap">
  
    <a class="tag-item" href="/coder957/tags/Java/" title="Java">Java (12)</a>
  
    <a class="tag-item" href="/coder957/tags/Spring/" title="Spring">Spring (9)</a>
  
    <a class="tag-item" href="/coder957/tags/kotlin/" title="kotlin">kotlin (7)</a>
  
    <a class="tag-item" href="/coder957/tags/Maven/" title="Maven">Maven (2)</a>
  
    <a class="tag-item" href="/coder957/tags/Hibernate/" title="Hibernate">Hibernate (2)</a>
  
    <a class="tag-item" href="/coder957/tags/kotlin-小知识/" title="kotlin 小知识">kotlin 小知识 (1)</a>
  
    <a class="tag-item" href="/coder957/tags/Kotlin/" title="Kotlin">Kotlin (1)</a>
  
    <a class="tag-item" href="/coder957/tags/Json/" title="Json">Json (1)</a>
  
    <a class="tag-item" href="/coder957/tags/热点文章/" title="热点文章">热点文章 (1)</a>
  
    <a class="tag-item" href="/coder957/tags/博主推荐/" title="博主推荐">博主推荐 (1)</a>
  
    <a class="tag-item" href="/coder957/tags/转载/" title="转载">转载 (1)</a>
  
    <a class="tag-item" href="/coder957/tags/资料/" title="资料">资料 (1)</a>
  
    <a class="tag-item" href="/coder957/tags/Ajax/" title="Ajax">Ajax (1)</a>
  
</div>
    </section>
    

    

    
    <!-- 友情链接 -->
    <section class="widget">
        <h3 class="widget-hd"><strong>友情链接</strong></h3>
        <!-- 文章分类 -->
<ul class="widget-bd">
    
        <li>
            <a href="http://lsc95.github.io/" target="_blank" title="椿哥的狗窝">椿哥的狗窝</a>
        </li>
    
        <li>
            <a href="http://futaosmile.oschina.io/documents/" target="_blank" title="donot click me">Document</a>
        </li>
    
        <li>
            <a href="" target="_blank" title="虚位以待">loading...</a>
        </li>
    
</ul>
    </section>
    
</aside>
<!-- / 侧栏部分 -->
    </div>

    <!-- 博客底部 -->
    <footer class="footer">
    &copy;
    
                2016-
                2017
                    

                        <a href="/coder957/">Loves You</a>
</footer>
<div class="back-to-top" id="JELON__backToTop" title="返回顶部">返回顶部</div>
    <!--博客js脚本 -->
    <!-- 这里放网站js脚本 -->
<script src="/coder957/js/main.js"></script>
</body>
</html>